package com.longteng.lesson2.thread;

/**
 * Created by li
 * DATE : 2018/11/25 0025
 * TIME : 22:58
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:55324936@qq.com">li</a>
 */
public class MyThread extends Thread {
    @Override
    public void run() {
        //2秒钟没有处理完成
        for(int i =1;i<10;i++){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"顺序:"+i);
        }
    }
    public static void main(String[] args) {
        //线程优先级的概念，并不是优先级高的要绝对执行完成，
        //只是获取cpu分配执行的时间资源较多
        System.out.println("主线程执行");
        MyThread myThread=new MyThread();
        myThread.setName("t1");
        myThread.setPriority(1);
        myThread.start();
//        MyThread myThread1=new MyThread();
//        myThread1.setName("t2");
//        myThread1.setPriority(10);
//        myThread1.start();
//        try {
//            Thread.sleep(200);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        //把子线程合并到主线程执行
        try {
            myThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("主线程执行完成");
    }
}
